//IdentityCodeValid("410527199011111111'),则返回false,表示无效
function IdentityCodeValid(code) {
    var tip = "";
    var pass = true;
    //15位转为18位
    if (code.length == '15') {
        var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
        var codeTemp = 0, i;
        code = code.substr(0, 6) + '19' + code.substr(6, code.length - 6);
        for (i = 0; i < 17; i++) {
            codeTemp += code.substr(i, 1) * arrInt[i];
        }
        code += arrCh[codeTemp % 11];
    }
    if (!code || !/^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|X|x)$/i.test(code)) {
        tip = "身份证号格式错误";
        pass = false;
    }
    else {
        //18位身份证需要验证最后一位校验位
        if (code.length == 18) {
            code = code.split('');
            //∑(ai×Wi)(mod 11)
            //加权因子
            var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
            //校验位
            var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
            var sum = 0;
            var ai = 0;
            var wi = 0;
            for (var i = 0; i < 17; i++) {
                ai = code[i];
                wi = factor[i];
                sum += ai * wi;
            }
            var last = parity[sum % 11];
            if (parity[sum % 11] != code[17].toUpperCase()) {
                tip = "校验位错误";
                pass = false;
            }
        }
    }
   // if (!pass) ps_alert(tip);
    return pass;
}